package com.hopu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hopu.pojo.Biao;
import com.hopu.pojo.Emp;
import com.hopu.pojo.Mybs;
import com.hopu.service.BiaoService;
import com.hopu.service.BsService;
import com.hopu.util.DateFormatGetTime;
import com.hopu.util.ResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/bs")
@RestController
public class BsController {
    @Resource
    private BsService bsServiceImpl;

    @PostMapping("/findAllBs")
    private ResultUtils findAllBs(@RequestParam(value = "current",defaultValue = "1") Integer current){

        try {
            PageHelper.startPage(current,6);
            List<Mybs> allBs = bsServiceImpl.findAllBs();

            PageInfo pageInfo = new PageInfo(allBs);
            return new ResultUtils(200,"查询页面成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtils(9999,"查询页面失败",null);
        }
    }

    /*@PostMapping("addBiao")
    public ResultUtils addBiao(
            HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "aid")int aid,
            @RequestParam(value = "hid")int hid,
            @RequestParam(value = "dkd")Float dkd,
            @RequestParam(value = "skd")Float skd,
            @RequestParam(value = "mkd")Float mkd,
            @RequestParam(value = "mtime")String mtime

    ){
        System.out.println("1111111111111111111111111");
        try {

            long mtime1 = DateFormatGetTime.getTime(mtime);


            Emp empLog = (Emp) request.getSession().getAttribute("empLog");

            int num = biaoServiceImpl.addBiao(aid,hid,dkd,skd,mkd,mtime1,empLog.getEid());

            if (num==0){
                return new ResultUtils(400,"ERROR",null);
            }
            return new ResultUtils(200,"SUCCESS",1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @PostMapping("/findBiaoByBid")
    public ResultUtils findBiaoByBid(int bid){

        Biao biao = biaoServiceImpl.findBiaoByBid(bid);

        return new ResultUtils(200,"查询页面成功",biao);

    }
    @PostMapping("uppBiao")
    public ResultUtils uppBiao(Biao biao, HttpSession session){

            // 获取session 当前登录账号信息
            Emp empLog = (Emp)session.getAttribute("empLog");
            biao.setEid(empLog.getEid());

           // biao.setMtime(DateFormatGetTime.getTime(mtime));


            int biao1 = biaoServiceImpl.uppBiao(biao);
            if (biao1<0){
                return new ResultUtils(400,"ERROR",null);
            }
            return new ResultUtils(200,"SUCCESS",1);


    }*/
}
